(function () {
  let usernameIpt = document.querySelector(".account");
  let nicknameIpt = document.querySelector(".username");
  let emailIpt = document.querySelector(".usermail");
  //重置模态框
  async function resetModal() {
    let res = await getUserinfo();
    usernameIpt.value = res.data.data.username;
    nicknameIpt.value = "";
    emailIpt.value = "";
  }
  document.querySelector("#btnReset").addEventListener("click", resetModal);
  async function initModel() {
    let res = await getUserinfo();
    console.log(res);
    let { username, nickname, email } = res.data.data;
    usernameIpt.value = username;
    nicknameIpt.value = nickname;
    emailIpt.value = email;
  }
  // 提交修改信息
  async function changeInfo() {
    let res1 = await getUserinfo();
    let { id, username, nickname, email, user_pic } = res1.data.data;
    let obj = {
      id: id,
      username: username,
      nickname: nicknameIpt.value,
      email: emailIpt.value,
      user_pic: user_pic,
    };
    let res = await userinfoChange(obj);
    resetModal();
  }
  document.querySelector("#submit").addEventListener("click", changeInfo);
  // (function () {
  // let usernameIpt = document.querySelector(".account");
  // let nicknameIpt = document.querySelector(".username");
  // let emailIpt = document.querySelector(".usermail");
  // // 重置模态框
  // async function resetModal() {
  // let res = await getUserinfo();
  // usernameIpt.value = res.data.data.username;
  // nicknameIpt.value = "";
  // emailIpt.value = "";
  // }
  // document.querySelector("#btnReset").addEventListener("click", resetModal);
  // //  初始化模态框
  // async function initModel() {
  // let res = await getUserinfo();
  // console.log(res);
  // let { username, nickname, email } = res.data.data;
  // usernameIpt.value = username;
  // nicknameIpt.value = nickname;
  // emailIpt.value = email;
  // }
  // initModel();
  // // 提示框
  // function hintMessage(hint, res) {
  // hint.style.opacity = 1;
  // hint.textContent = res
  // setTimeout(() => {
  // hint.style.opacity = 0;
  // }, 2000);
  // }
  // //  提交修改信息
  // async function changeInfo() {
  // let res1 = await getUserinfo();
  // let { id, username, nickname, email, user_pic } = res1.data.data;
  // let obj = {
  // id: id,
  // username: username,
  // nickname: nicknameIpt.value,
  // email: emailIpt.value,
  // user_pic: user_pic,
  // };
  // let res = await userinfoChange(obj);
  // let hint = document.querySelector(".hint");
  // let message = res.data.message
  // if (res.data.code === 0) {
  // hintMessage(hint,message);
  // initModel();
  // } else {
  // hintMessage(hint,message);
  // resetModal();
  // }
  // }
  // document.querySelector("#submit").addEventListener("click", changeInfo);
  //   })();
})();
